package top.wettis.chat.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.wettis.chat.constant.ResultCode;
import top.wettis.chat.constant.ResultType;
import top.wettis.chat.pojo.DO.HistoryRecord;
import top.wettis.chat.pojo.DO.JobImfor;
import top.wettis.chat.pojo.VO.Result;
import top.wettis.chat.service.impl.HistoryRecordServiceImpl;

/**
 * <p>
 * 用户提问历史记录 前端控制器
 * </p>
 *
 * @author wettis
 * @since 2023-03-25
 */
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/chat/historyRecord")
public class HistoryRecordController {
    @Autowired
    private HistoryRecordServiceImpl historyRecordService;
    /**
     * 查询列表
     */
    @GetMapping("/list")
    @ResponseBody
    private Result<Object> selectall() {
        return historyRecordService.selectAll();
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public Result<Object> Save(@RequestBody HistoryRecord historyRecord) {

        historyRecordService.save(historyRecord);
        return Result.successInfo(ResultType.SAVE, "添加成功");
    }

    /**
     * 删除
     */

    @DeleteMapping("/delete/{id}")
    public Result<Object> Delete(@PathVariable Integer id) {
        historyRecordService.removeById(id);
        return Result.successInfo(ResultType.DELETE, ResultCode.DELETE_OK);
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result<Object> Update(@RequestBody HistoryRecord historyRecord) {
        historyRecordService.updateById(historyRecord);
        return Result.successInfo(ResultType.UPDATE, ResultCode.UPDATE_OK);
    }


    /**
     * 查询id
     */
    @GetMapping("/select/{id}")
    public Result<Object> select(@PathVariable Integer id) {
        HistoryRecord historyRecord = historyRecordService.getById(id);
        if (historyRecord != null) {
            return Result.successInfo(ResultType.GET, ResultCode.GET_OK);
        } else {
            return Result.successInfo(ResultType.GET, ResultCode.GET_ERR);
        }

    }




}
